package com.d2rv.offscreen;

import com.d2rv.guide.GoalManager;
import com.d2rv.model.CityModelManager;
import com.d2rv.user.UserManager;
import processing.core.PApplet;
import processing.core.PVector;

/**
 * This class of the offscreen guide map.
 *
 * @author Darrieutort A., Dupouy A., Rossignol L., Van Poucke A.
 */
public class OffScreenGuideMap extends OffScreen3D {

    private UserManager usermanager;
    private CityModelManager citymodelmanager;
    private GoalManager goalmanager;

    /**
     * Default constructor.
     * 
     * @param parent the current application
     * @param width the width of the offscreen
     * @param height the height of the offscreen
     * @param multi the boolean that indicates if the multisampling is used 
     * @param level
     * @param usermanager the manager of the user
     * @param citymodelmanager the manager of the city model
     * @param goalmanager the manager of the goal
     */
    public OffScreenGuideMap(PApplet parent, int width, int height, boolean multi, int level,
            UserManager usermanager, CityModelManager citymodelmanager, GoalManager goalmanager) {
        super(parent, width, height,
                new PVector(usermanager.user().position().x, usermanager.user().position().y, usermanager.user().position().z),
                new PVector(usermanager.user().position().x, usermanager.user().position().y, usermanager.user().position().z),
                new PVector(0, 0, 1));
        this.usermanager = usermanager;
        this.citymodelmanager = citymodelmanager;
        this.goalmanager = goalmanager;
    }

    /**
     *  Calls the draw method of the differents objects
     */
    public void draw() {
        beginDraw();
        background(255, 255, 255);
        this.cameramanager.updateCamera(new PVector(this.usermanager.user().position().x, this.usermanager.user().position().y + 190, this.usermanager.user().position().z), this.usermanager.user().position());
        this.cameramanager.camera(this);
        this.citymodelmanager.drawCity(this);
        this.usermanager.drawUser(this);
        this.goalmanager.drawObjectifGuide(this, this.usermanager.user().position());
        endDraw();
    }

    /**
     * loads the image in the texture of the offscreen
     *
     * @param parent the current application
     * @param x the x coordinate of the left corner of the offscreen
     * @param y the y coordinate of the left corner of the offscreen
     */
    public void show(PApplet parent, int x, int y) {
        parent.image(getTexture(), x, y, this.width, this.height);
    }

    /**
     *
     * @param zoom
     */
    public void updateCameraZoom(float zoom) {
        this.cameramanager.updateZoomCamera(zoom);
    }

    /**
     *
     * @return
     */
    public float zoomCamera() {
        return this.cameramanager.zoomCamera();
    }
}